﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.Helper;
using BCGC.BLL.Forum;

public partial class Admin_Forum_edit_postCategory : AdminBasePage
{
    private int ID
    {
        get
        {
            if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]) == false)
                return Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);

            return -1;
        }
    }


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    private void LoadData()
    {
        PostCategory postCat = ForumManager.GetPostCategoryByID(ID);
        if (postCat != null)
        {
            txtCategoryName.Text = postCat.CategoryName;
            txtTotalPost.Text = postCat.TotalPost.ToString();
            chkIsActive.Checked = postCat.IsActive;
            fckContent.Value = Server.HtmlDecode(postCat.Description);
        }
    }

    protected void imbSave_Click(object sender, EventArgs e)
    {
        PostCategory postCat = ForumManager.GetPostCategoryByID(ID);
        if (postCat != null)
        {
            postCat.CategoryName = txtCategoryName.Text.Trim();
            postCat.TotalPost = Convert.ToInt32(txtTotalPost.Text.Trim());
            postCat.IsActive = chkIsActive.Checked;
            postCat.Description =Server.HtmlEncode(fckContent.Value);
            if (ForumManager.SavePostCategory(postCat))
            {
                uccResponse.SetSuccessMessage("PostCategory successfuly updated");
            }
            else
            {
                uccResponse.SetFailMessage("Failed to update PostCategory");
            }
        }
    }
}
